package com.training.micrservices.eureka.controller;

import org.apache.commons.io.FileUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("/eureka")
public class TestController {

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

    /**
     * 多文件文件上传
     *
     * @param file 文件流
     * @return URL
     */
    @RequestMapping("/upload")
    public Object upload(@RequestPart("fileList") MultipartFile file) {
        try (InputStream inputStream = file.getInputStream()) {
            FileUtils.copyInputStreamToFile(inputStream, new File("E:/upload", file.getOriginalFilename()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return file.getOriginalFilename();
    }
}